package 操作文件内容;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Filedemo3 {
    public static void main(String[] args) {
        //创建 OutputStream实例，来打开文件，会将文件中原来的内容清空
        try(OutputStream outputStream=new FileOutputStream("./hello.txt")) {
            //write 每次写入一个字节8 或 字符16

            //按照字符写入
            //outputStream.write('a');
            //outputStream.write('b');
             //outputStream.write('c');

            //按照字节写入
            //byte[] buffer=new byte[] {
            //        (byte)'a',(byte)'b',(byte)'c',(byte)'d'
            //};
            //outputStream.write(buffer);

            //按照字符串写入
            String s="hello  sj";
            outputStream.write(s.getBytes());


        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
